home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / except.zip / B4DMSGRS.CPP < prev    next >
C/C++ Source or Header  |  1993-03-02  |  2KB  |  67 lines

  1. //---------------------------------------------------------------------
  2. // b4dmsgrs.cpp    2-28-93    djf
  3. // B4DMsgResource class definitiion
  4. //---------------------------------------------------------------------
  5.  
  6. //---------------------------------------------------------------------
  7. // includes
  8. //---------------------------------------------------------------------
  9. #include "b4dmsg.h"
  10. #include "b4dmsgrs.h"
  11.  
  12. B4DMsgResource::B4DMsgResource()
  13. {
  14.     if ((hLib = LoadLibrary ((LPTSTR)"b4dmsg.dll")) == NULL)
  15.         RaiseException
  16.             (
  17.             B4D_ERROR_LOAD_LIBRARY_FAILED,
  18.             EXCEPTION_NONCONTINUABLE,
  19.             0,
  20.             NULL            
  21.             );
  22.  
  23. } // B4DMsgResource::B4DMsgResource()
  24.  
  25. B4DMsgResource::~B4DMsgResource()
  26. {
  27.     FreeLibrary( hLib );
  28. } // B4DMsgResource::~B4DMsgResource()
  29.  
  30. // get the message associated with exception code
  31. const char *B4DMsgResource::get        
  32.     ( 
  33.     DWORD     dwExceptionCode,
  34.     DWORD    *pArgs
  35.     ) const
  36. {
  37.     static const int BUF_LEN = 256;
  38.     static char buffer[BUF_LEN];
  39.  
  40.     int nBytesRead = 
  41.         FormatMessage
  42.             (
  43.             FORMAT_MESSAGE_FROM_HMODULE,
  44.             hLib,
  45.             dwExceptionCode, 
  46.             0,    // language - I don't know where this comes from
  47.             buffer,
  48.             BUF_LEN,
  49.             pArgs
  50.             );
  51.  
  52.     // I don't think we should throw an exception here if the 
  53.     // LoadString fails:  too much chance of endless loop.
  54.     if ( !nBytesRead )
  55.         wsprintf
  56.             ( 
  57.             buffer, 
  58.             "Unknown B4D Exception 0x%lX",
  59.             dwExceptionCode,
  60.             GetLastError()
  61.             );
  62.  
  63.     return buffer;
  64.     
  65. } // const char *B4DMsgResource::get
  66.  
  67.